<?php

namespace Admin\Controller;
use Think\Controller;

class LinkController extends Controller{

        function showlist(){
            $link=new \Model\LinkModel();
            $link_info=$link->order('id desc')->select();
            $this->assign('link_info',$link_info);
            $this->display();
        }



    function shanchu($id){
        $link=M('Link');
        $return=$link->delete($id);
        if($return){
            $this->redirect('showlist',array(),'0','删除成功');
        }else{
            $this->redirect('showlist',array(),'2','删除失败');
        }
        $this->display();
    }
    function update($id){
        $link=M('Link');
        if(!empty(I('POST.url'))){
            $return=$link->where("id=$id")->save(I('POST.'));
            if($return){
                $this->redirect('showlist',array(),'1','<h2>修改成功</h2>');
            }else{
                $this->redirect('update',array('id'=>$id),'5','<h2>修改失败</h2>');
            }
        }
        $info=$link->find($id);
        dump($info);
        $this->assign('info',$info);
        $this->display();
    }

    function add(){
        $link=M('Link');
        if(!empty(I('post.url'))){
            $return=$link->add(I('post.'));
            if($return){
                $this->redirect('showlist',array(),1,'添加成功');
            }else{
                $this->redirect('add',array(),3,"添加失败");
            }
        }

        $this->display();
    }
}

?>
